package com.lhq.business.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhq.business.domain.BookTag;
import com.lhq.business.service.IBookTagService;
import com.lhq.common.annotation.Log;
import com.lhq.common.core.controller.BaseController;
import com.lhq.common.core.domain.AjaxResult;
import com.lhq.common.enums.BusinessType;
import com.lhq.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 图书标签对应Controller
 *
 * @author lhq
 * @date 2024-05-11
 */
@RestController
@RequestMapping("/business/book/tag")
public class BookTagController extends BaseController
{
    @Autowired
    private IBookTagService bookTagService;

    /**
     * 查询图书标签对应列表
     */
    @PreAuthorize("@ss.hasPermi('business:tag:list')")
    @GetMapping("/list")
    public AjaxResult list(BookTag bookTag,
                             @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize)
    {
        Page<BookTag> page =new Page<>(pageNum,pageSize);
        return AjaxResult.successPage(bookTagService.selectList(page,bookTag));
    }

    /**
     * 导出图书标签对应列表
     */
    @PreAuthorize("@ss.hasPermi('business:tag:export')")
    @Log(title = "图书标签对应", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookTag bookTag,
                       @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize)
    {
        Page<BookTag> page =new Page<>(pageNum,pageSize);
        List<BookTag> list = bookTagService.selectList(page,bookTag).getRecords();
        ExcelUtil<BookTag> util = new ExcelUtil<BookTag>(BookTag.class);
        util.exportExcel(response, list, "图书标签对应数据");
    }

    /**
     * 获取图书标签对应详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:tag:query')")
    @GetMapping(value = "/{bookId}")
    public AjaxResult getInfo(@PathVariable("bookId") String bookId)
    {
        return success(bookTagService.selectById(bookId));
    }

    /**
     * 新增图书标签对应
     */
    @PreAuthorize("@ss.hasPermi('business:tag:add')")
    @Log(title = "图书标签对应", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BookTag bookTag)
    {
        return toAjax(bookTagService.insertBookTag(bookTag));
    }

    /**
     * 修改图书标签对应
     */
    @PreAuthorize("@ss.hasPermi('business:tag:edit')")
    @Log(title = "图书标签对应", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BookTag bookTag)
    {
        return toAjax(bookTagService.updateBookTag(bookTag));
    }

    /**
     * 删除图书标签对应
     */
    @PreAuthorize("@ss.hasPermi('business:tag:remove')")
    @Log(title = "图书标签对应", businessType = BusinessType.DELETE)
	@GetMapping("/del/{bookId}")
    public AjaxResult remove(@PathVariable("bookId") Long  bookId)
    {
        return toAjax(bookTagService.deleteByBookId(bookId));
    }
}
